package jobqueue;

import java.util.Date;
import predictors.ProbaInfo;
import utils.Utils;
import data.ClusterInfo;
import data.UserInfo;
import jsonobj.JobInfo;

public class JobQueueInfo {
	private JobInfo ji;
	private Date schedule;
	private ClusterInfo ci;
	
	public JobQueueInfo(JobInfo j,Date s, ClusterInfo c)
	{
		this.ji = j;
		this.schedule = s;
		this.ci = c;
	}
	public JobQueueInfo(JobInfo j,ProbaInfo i, UserInfo ui)
	{
		this.ji = j;
		this.schedule = i.h_prob.time;
		this.ci = ui.clusters.get(i.cluster);
	}
	
	public void sheduleAt(Date d)
	{
		this.schedule = (Date) d.clone();
	}
	public boolean isBefore(Date d)
	{
		return schedule.compareTo(d) <= 0;
	}
	public Date getSchedule()
	{
		return this.schedule;
	}
	public void submitJob()
	{
		try{
			//Utils.out("JOB SUBMISSION: "+ji.jname+" "+ji.clu+" "+schedule);
			if(ci.isConnected)
				ci.sendMessage(ji);	
		}catch(Exception e){e.printStackTrace();}
	}
}
